package com.tust.app.service.impl;

import com.tust.app.dao.NewsMapper;
import com.tust.app.domain.News;
import com.tust.app.service.NewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewService {

    @Autowired
    private NewsMapper newsMapper;


    public List<News> getAllNews(){

            List<News> newsList=newsMapper.selectAllNews();
            return newsList;



    }

    @Override
    public List<News> search(String title) {
        if (title != null && title.length() > 0) {
            return newsMapper.selectNewsByTitle(title);
        } else {
            return null;
        }
    }

    @Override
    public Integer addArticle(News news) {

        return newsMapper.writeNews(news);
    }

    @Override
    public News findNewsById(Integer id) {


        return newsMapper.selectNewsById(id);

    }

    @Override
    public boolean modifyNews(News news) {
        return newsMapper.updateNews(news);
    }

    @Override
    public boolean delNews(Integer id) {


        return newsMapper.deleteNewsById(id);
    }


}
